﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using OnlineVideos.Services.OnlineVideoService;
using System.Collections.ObjectModel;
using OnlineVideos.Services.FileStoreService;
using System.Threading.Tasks;

namespace Common.Services
{

    public static class ServiceManager
    {
        public static void RetrieveuserDataAsync(byte[] AnonymousId, string ApplicationName, string ID, EventHandler<RetrieveuserDataCompletedEventArgs> callback)
        {
            OnlineVideoServiceClient client = new OnlineVideoServiceClient();
            client.RetrieveuserDataAsync(BitConverter.ToString(AnonymousId), ApplicationName, Convert.ToInt32(ID));
            client.RetrieveuserDataCompleted += new EventHandler<RetrieveuserDataCompletedEventArgs>(callback);
        }
        // public static void SendPeopleImageBytesToAppAsync(string applicationName, string personImage, EventHandler<SendPeopleImageBytesToAppCompletedEventArgs> callback)
        //{
        //    ImageServiceClient Imgclient = new ImageServiceClient();
        //    Imgclient.SendPeopleImageBytesToAppAsync(applicationName,personImage);
        //    Imgclient.SendPeopleImageBytesToAppCompleted += new EventHandler<SendPeopleImageBytesToAppCompletedEventArgs>(callback);
        //}

        // public static void SendPovitImageBytesToAppAsync(string Appname,string PivotImagePath,EventHandler<SendPovitImageBytesToAppCompletedEventArgs>callback)
        // {
        //     ImageServiceClient Imgclient = new ImageServiceClient();
        //     Imgclient.SendPovitImageBytesToAppAsync(Appname, PivotImagePath);
        //     Imgclient.SendPovitImageBytesToAppCompleted += new EventHandler<SendPovitImageBytesToAppCompletedEventArgs>(callback);
        // }

        // public static void SendImageBytesToAppAsync(string ApplicationName, string ImagePath, string ShowId, EventHandler<SendImageBytesToAppCompletedEventArgs> callback)
        // {
        //     ImageServiceClient Imgclient = new ImageServiceClient();
        //     Imgclient.SendImageBytesToAppAsync(ApplicationName, ImagePath, ShowId);
        //     Imgclient.SendImageBytesToAppCompleted += new EventHandler<SendImageBytesToAppCompletedEventArgs>(callback);
        // }

        public static void RestoreParentalControlPreferences(byte[] AnonymousID, string ApplicationName, string ID, EventHandler<RetrieveParentalControlDataCompletedEventArgs> callback)
        {
            OnlineVideoServiceClient client = new OnlineVideoServiceClient();
            client.RetrieveParentalControlDataAsync(BitConverter.ToString(AnonymousID), ApplicationName, Convert.ToInt32(ID));
            client.RetrieveParentalControlDataCompleted += new EventHandler<RetrieveParentalControlDataCompletedEventArgs>(callback);
        }

        public static void Restoreratingvideos(string rdate, string ApplicationName, string ID, EventHandler<getRatingVideosnextupdateddateCompletedEventArgs> callback)
        {
            OnlineVideoServiceClient client = new OnlineVideoServiceClient();
            client.getRatingVideosnextupdateddateAsync(rdate, ApplicationName, Convert.ToInt32(ID));
            client.getRatingVideosnextupdateddateCompleted += new EventHandler<getRatingVideosnextupdateddateCompletedEventArgs>(callback);
        }
        public static void Restorerating(string rdate, string ApplicationName, string ID, EventHandler<getRatingnextupdateddateCompletedEventArgs> callback)
        {
            OnlineVideoServiceClient client = new OnlineVideoServiceClient();
            client.getRatingnextupdateddateAsync(rdate, ApplicationName, Convert.ToInt32(ID));
            client.getRatingnextupdateddateCompleted += new EventHandler<getRatingnextupdateddateCompletedEventArgs>(callback);
        }
        public static void GetBlogDetails(string Category, string ApplicationName, EventHandler<GetUsernameandPasswordCompletedEventArgs> callback)
        {
            OnlineVideoServiceClient client = new OnlineVideoServiceClient();
            client.GetUsernameandPasswordAsync(Category, ApplicationName);
            client.GetUsernameandPasswordCompleted += new EventHandler<GetUsernameandPasswordCompletedEventArgs>(callback);
            //ObservableCollection<BlogInfo> binfo = Task.Run(async () => await client.GetUsernameandPasswordAsync(Category, ApplicationName)).Result;
            //return binfo;

        }
        public static void InsertUserData(ObservableCollection<Favorites> fav)
        {
            OnlineVideoServiceClient client = new OnlineVideoServiceClient();
            client.InsertUserDataAsync(fav);
        }
        public static void InsertParentalControlData(ObservableCollection<Favorites> fav)
        {
            OnlineVideoServiceClient client = new OnlineVideoServiceClient();
            client.InsertParentalControlDataAsync(fav);
        }
        public static void GetRatingvideos(ObservableCollection<Favorites> fav, EventHandler<GetRatingvideosCompletedEventArgs> callback)
        {
            OnlineVideoServiceClient client = new OnlineVideoServiceClient();
            client.GetRatingvideosAsync(fav);
            client.GetRatingvideosCompleted += new EventHandler<GetRatingvideosCompletedEventArgs>(callback);
        }

        public static void GetRating(ObservableCollection<Favorites> fav, EventHandler<GetRatingCompletedEventArgs> callback)
        {
            OnlineVideoServiceClient client = new OnlineVideoServiceClient();
            client.GetRatingAsync(fav);
            client.GetRatingCompleted += new EventHandler<GetRatingCompletedEventArgs>(callback);
        }

        public static void GetSearchHistory(ObservableCollection<Favorites> searchhis, EventHandler<GetSearchHistoryCompletedEventArgs> callback)
        {
            OnlineVideoServiceClient client = new OnlineVideoServiceClient();
            client.GetSearchHistoryAsync(searchhis);
            client.GetSearchHistoryCompleted += new EventHandler<GetSearchHistoryCompletedEventArgs>(callback);
        }
        public static void SendMailToAppAsync(string fromAddress, string Toaddress, string subject, string body, EventHandler<SendMailCompletedEventArgs> callback)
        {
            try
            {
                Service1Client FileStoreclient = new Service1Client();
                FileStoreclient.SendMailAsync(fromAddress, Toaddress, subject, body);
                FileStoreclient.SendMailCompleted += new EventHandler<SendMailCompletedEventArgs>(callback);
            }
            catch (Exception ex)
            {

            }
        }
    }
}
